var api_url = "http://beta.hellotxt.com/apiv2/app";
var app_key = "Ad84faktq7BFHadC";
localStorage.app_key = app_key;

function getApiData(operation, user_key, app_key, json, callback) {
	var req = new XMLHttpRequest();
	var url = api_url + "?operation=" + operation + "&user_key=" + user_key + "&app_key=" + app_key + "&json=" + JSON.stringify(json);
	console.debug(url);
	req.open("GET", url, true);
	req.onreadystatechange = function() {
		if(req.readyState == 4) {
			console.debug(req.responseText);
			var resp = JSON.parse(req.responseText);			
			callback(resp);
		}
	};
	req.send();
};

function apiSignin(username, password, callback) {
	var req = new XMLHttpRequest();
	var json = {
			"username": username,
			"password": password,
			"action": "signin",
			"reg_source": "chrome_ext",
			"device": {
				"type":"api",
				"app_key":app_key,
				"user_key":"empty"
			}
	};
	var url = api_url + "?operation=user&json=" + JSON.stringify(json);
	console.debug(url);
	req.open("GET", url, true);
	req.onreadystatechange = function() {
		if(req.readyState == 4) {
			console.debug(req.responseText);
			var resp = JSON.parse(req.responseText);
			callback(resp);
		}
	};
	req.send();
}